package com.joney.common.exception;


import com.joney.common.enums.GlobalErrorCodeEnum;
import com.joney.common.enums.IEnum;

/**
* @author wangxianchen
* @create 2017-09-01
* @desc 自定义异常类
*/
public class DefaultException extends RuntimeException {

    private IEnum errorCodeEnum;

    private Object param;

    public DefaultException() {
        super();
        errorCodeEnum = GlobalErrorCodeEnum.FAIL;
    }
    public DefaultException(Object param) {
        super();
        this.param = param;
        errorCodeEnum = GlobalErrorCodeEnum.FAIL;
    }

    public DefaultException(IEnum errorCodeEnum) {
        super(errorCodeEnum.msg());
        this.errorCodeEnum = errorCodeEnum;
    }

    public DefaultException(IEnum errorCodeEnum, Object param) {
        super(errorCodeEnum.msg());
        this.errorCodeEnum = errorCodeEnum;
        this.param = param;
    }


    public DefaultException(String message) {
        super(message);
        GlobalErrorCodeEnum errorEnum = GlobalErrorCodeEnum.FAIL;
        errorEnum.setMsg(message);
        errorCodeEnum = errorEnum;
    }


    public DefaultException(Throwable cause) {
        super(cause);
    }


    public DefaultException(String message, Throwable cause) {
        super(message, cause);
    }

    public IEnum getErrorCodeEnum() {
        return errorCodeEnum;
    }

    public Object getParam() {
        return param;
    }

    public void setParam(Object param) {
        this.param = param;
    }

    @Override
    public String toString() {
        return "DefaultException{" +
                "code=" + errorCodeEnum.code() +
                "msg=" + errorCodeEnum.msg() +
                ", param=" + (param == null ? null : param.toString()) +
                '}';
    }
}
